package com.example.java2024_5_1searcher.controller;

import com.example.java2024_5_1searcher.searcher.DoSearcher;
import com.example.java2024_5_1searcher.searcher.Result;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RequestMapping("/search")
@RestController
public class SearchController {
    DoSearcher doSearcher=new DoSearcher();
    ObjectMapper objectMapper=new ObjectMapper();
    @RequestMapping(value = "/do", produces = "application/json;charset=utf-8")
    public String doSearch(String query) throws JsonProcessingException {
       ArrayList<Result> results=doSearcher.Search(query);
        return objectMapper.writeValueAsString(results);
    }
}
